package org.zxp.designpattern.iterator;

import java.util.Iterator;

/**
 * @program: effectiveJava
 * @description:
 * @author: X-Pacific zhang
 * @create: 2019-08-29 11:49
 **/
public class MyBookStore {
    private String[] bookNames = {"redis设计与实现", "java并发编程", "redis in action", "深入理解java虚拟机", "数学之美", "effective java", "unix网络编程"};

    public Iterator iterator(){
        return new BookIterator(bookNames);
    }

    static class BookIterator implements Iterator<String> {
        private String[] items;
        private int index;

        public BookIterator(String[] items) {
            this.items = items;
        }


        @Override
        public boolean hasNext() {
            if (index >= items.length)
                return false;
            return true;
        }

        @Override
        public String next() {
            if (index > items.length)return null;
            return items[index++];
        }
    }

}
